package com.example.demo0.c0



interface Computer
class Dell:Computer
class Asus:Computer
class Acer:Computer


open abstract class AbstractFactory {
    abstract fun produce():Computer
    companion object{
        operator fun invoke(factory: AbstractFactory):AbstractFactory{
            return factory
        }
        inline operator fun <reified T:Computer> invoke():AbstractFactory=
            when(T::class){
                Dell::class ->DellFactory()
                Asus::class ->AsusFactory()
                Acer::class ->AcerFactory()
                else -> throw IllegalArgumentException()
            }
    }
}

class DellFactory:AbstractFactory(){
    override fun produce() = Dell()
}

class AsusFactory: AbstractFactory() {
    override fun produce() = Asus()
}

class AcerFactory:AbstractFactory(){
    override fun produce()=Acer()

}

class Robot private constructor(
    val code:String,
    val batter:String?,
    val height:Int?,
    val weight:Int?
){
    class Builder(val code:String){
        private var battery:String? = null
        private var height:Int? = null
        private var weight:Int? = null

        fun setBattery(battery:String?):Builder{
            this.battery = battery
            return this
        }

        fun setHeight(height: Int):Builder{
             this.height = height
            return this
        }

        fun setWeight(weight: Int):Builder{
            this.weight = weight
            return this
        }

        fun build():Robot{
            return Robot(code,battery,height,weight)
        }

    }
}












